package com.fho4565.core.timer;

import org.jetbrains.annotations.NotNull;

import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;

public class Timer implements Serializable ,Comparable<Timer>{
    @Serial
    private static final long serialVersionUID = 3904230952686542781L;
    private String name;
    private int interval;
    private String Command;
    private boolean enabled = false;
    private int remainingTime;

    public int getRemainingTime() {
        return remainingTime;
    }

    public void setRemainingTime(int remainingTime) {
        this.remainingTime = remainingTime;
    }

    public boolean isSilent() {
        return isSilent;
    }

    public void setSilent(boolean silent) {
        isSilent = silent;
    }

    private boolean isSilent = true;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getInterval() {
        return interval;
    }

    public void setInterval(int interval) {
        this.interval = interval;
    }

    public String getCommand() {
        return Command;
    }

    public void setCommand(String command) {
        Command = command;
    }

    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public Timer(String name, int interval, String command) {
        this.name = name;
        this.interval = interval;
        Command = command;
    }
    public Timer(String name, int interval, String command, boolean enabled) {
        this.name = name;
        this.interval = interval;
        Command = command;
        this.enabled = enabled;
    }

    public boolean countDown() {
        if (!enabled) {
            return false;
        }
            if (remainingTime > 0) {
                remainingTime--;
                return false;
            } else {
                remainingTime = interval;
                return true;
            }
    }
    public void reset(){
        this.remainingTime = interval;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        Timer another = (Timer) obj;
        return name.equals(another.name);
    }
    @Override
    public int compareTo(@NotNull Timer o) {
        return this.name.compareTo(o.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }
}
